#!/usr/bin/env python
"""
脚本用于显示所有BookInstance的ID，帮助找到正确的UUID用于renew URL
"""
import os
import sys
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'locallibrary.settings')
django.setup()

from catalog.models import BookInstance

def show_bookinstance_ids():
    """显示所有BookInstance的ID和相关信息"""
    print("所有BookInstance的ID:")
    print("-" * 80)
    
    book_instances = BookInstance.objects.all()
    
    if not book_instances:
        print("数据库中没有BookInstance记录")
        return
    
    for instance in book_instances:
        print(f"ID: {instance.id}")
        print(f"书名: {instance.book.title if instance.book else '无书名'}")
        print(f"状态: {instance.get_status_display()}")
        print(f"借阅者: {instance.borrower.username if instance.borrower else '无'}")
        print(f"到期日期: {instance.due_back}")
        print(f"Renew URL: http://127.0.0.1:8000/catalog/book/{instance.id}/renew/")
        print("-" * 80)

if __name__ == '__main__':
    show_bookinstance_ids() 